package com.game.majiang.algorithm.doudizhu;



import java.util.ArrayList;
import java.util.Random;

import lombok.Data;

@Data
public class Card {
	
	int _value;
	
	public String name;
	
	public Card(int b)//3->2
	{
		_value = b;
		name = String.valueOf(b);
	}
	public Card(String _name, ArrayList<Card> cards)
	{
		if(_name.equals("3"))
		{
			_value = 1;
		}
		else if(_name.equals("4"))
		{
			_value = 2;
		}
		else if(_name.equals("5"))
		{
			_value = 3;
		}
		else if(_name.equals("6"))
		{
			_value = 4;
		}
		else if(_name.equals("7"))
		{
			_value = 5;
		}
		else if(_name.equals("8"))
		{
			_value = 6;
		}
		else if(_name.equals("9"))
		{
			_value = 7;
		}
		else if(_name.equals("10"))
		{
			_value = 8;
		}
		else if(_name.equals("j"))
		{
			_value = 9;
		}
		else if(_name.equals("q"))
		{
			_value = 10;
		}
		else if(_name.equals("k"))
		{
			_value = 11;
		}
		else if(_name.equals("a"))
		{
			_value = 12;
		}
		else if(_name.equals("2"))
		{
			_value = 13;
		}
		else if(_name.equals("x"))
		{
			_value = 53;
		}
		else if(_name.equals("d"))
		{
			_value = 54;
		}
		else if(_name.equals("h"))
		{
			_value = 55;
		}
		if(_value != 53 && _value != 54 && _value != 55)
		{
			while(true)
			{
				Random t = new Random();
				int tt = t.nextInt(4);
				byte _value2 = (byte) (_value+tt*13);
				boolean fl = false;
				for(int i=0; i<cards.size(); i++)
				{
					if(_value2 == cards.get(i)._value)
					{
						fl = true;
						break;
					}
				}
				if(!fl)
				{
					_value = _value2;
					break;
				}
			}
		}
		name = String.valueOf(_value);
	}
	/*
	public byte getPaimian()
	{
		int residue = _value %13;
		if(residue == 0)
			return (byte)13;
		return (byte)residue; 
	}
	*/
	
	public int getWeight()
	{
		int residue = _value %13;
		if(getHuase() == Huase.King || getHuase() == Huase.Hua)
		{
			return (residue+13);
		}
		
		if(residue == 0)
			return 13;
		return residue;
	}
	
	
	public String getPaimians()
	{
		int residue = _value %13;
		if(residue < 9&&residue!=0)
			return String.valueOf(residue+2);
		else
		{
			if(residue == 9)
			{
				return "J";
			}
			if(residue == 10)
			{
				return "Q";
			}
			if(residue == 11)
			{
				return "K";
			}
			else if(residue == 12)
			{
				return "A";
			}
			else if(residue == 0)
			{
				return "2";
			}
			else
			{
				return "牌面错误";
			}
		}
	}
	
	
	//��ɫ
	public Huase getHuase()
	{
		if(_value < 14)
		{
			return Huase.Heitao;
		}
		else if(_value < 27)
		{
			return Huase.Hongtao;
		}
		else if(_value < 40)
		{
			return Huase.Meihua;
		}
		else if(_value < 53)
		{
			return Huase.Fankuai;
		}
		else if (_value < 55) {
			return Huase.King;
		} 
		else
		{
			return Huase.Hua;
		}
	}
	
	@Override
	public String toString() {
		if(_value == 53)
		{
			return "小王";
		}
		if(_value == 54)
		{
			return "大王";
		}
		if(_value == 55)
		{
			return "花牌";
		}
		return getHuase() +":"+getPaimians();
	}
	
	
}
